﻿using System;
using System.Collections.Generic;
using System.Web;

/// <summary>
///BlogAccountProxy 的摘要说明
/// </summary>
public class BlogAccountProxy
{
	public BlogAccountProxy()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}

    public BlogAccountData Add(string account, string des, string accessToken, DateTime expireIn)
    {
        DBBlogAccount db = new DBBlogAccount();
        BlogAccountData data = db.Select(account);
        if (data != null)
        {
            db.Update(account, des, accessToken, expireIn);
        }
        else
        {
            db.Add(account, des, accessToken, expireIn);
        }
        return db.Select(account);
    }

    public List<BlogAccountData> SelectList()
    {
        return new DBBlogAccount().SelectList();
    }

    /// <summary>
    /// 删除微博帐号，如果存在，则删除，并返回删除的微博帐号
    /// 如果不存在，返回null
    /// </summary>
    /// <param name="blogAccountId"></param>
    /// <returns></returns>
    public BlogAccountData Delete(int blogAccountId)
    {
        DBBlogAccount db = new DBBlogAccount();
        BlogAccountData data = db.Select(blogAccountId);
        if (data != null)
        {
            db.Delete(blogAccountId);           //删除微博信息
            DBUser dbuser = new DBUser();   //删除和系统帐号的对应关系
            dbuser.DeleteBolgAccountMapByBlogId(blogAccountId);
            //删除要使用此帐号发送的微博
            new DBDelaySendWeibo().DeleteList(data.account);
        }
        return data;
    }
}